//
//  CarGooodsTableViewCell.m
//  Shengzhuli
//
//  Created by 卡忙科技 on 16/8/2.
//  Copyright © 2016年 kamangkeji. All rights reserved.
//

#import "CarGooodsTableViewCell.h"
#import <UIImageView+WebCache.h>

@interface CarGooodsTableViewCell()
@property (weak, nonatomic) IBOutlet UIButton *checkBtn;
@property (weak, nonatomic) IBOutlet UIImageView *iconImage;
@property (weak, nonatomic) IBOutlet UILabel *titleLab;
@property (weak, nonatomic) IBOutlet UILabel *countLab;
@property (weak, nonatomic) IBOutlet UIButton *minusBtn;
@property (weak, nonatomic) IBOutlet UIButton *addBtn;
@property (weak, nonatomic) IBOutlet UILabel *priceLab;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *titleCons;



@end
@implementation CarGooodsTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
}
- (IBAction)selectBtn:(UIButton *)btn
{
    btn.selected = !btn.selected;
    self.model.isSelect = btn.selected;
    if ([self.delegate respondsToSelector:@selector(CarGooodsTableViewCellBtnAction:label:model:)]) {
        [self.delegate CarGooodsTableViewCellBtnAction:(AmountType)btn.tag label:nil model:self.model];
    }
}
- (IBAction)addMinusClick:(UIButton *)btn
{
    NSInteger count = [self.countLab.text integerValue];
    switch (btn.tag) {
        case 2:
        {
            if ((count-1)<1) {
                self.minusBtn.userInteractionEnabled = NO;
                return;
            }
            self.addBtn.userInteractionEnabled = YES;
        }
            break;
        case 1:
        {
            self.minusBtn.userInteractionEnabled = YES;
        }
            break;
        default:
            break;
    }
    if ([self.delegate respondsToSelector:@selector(CarGooodsTableViewCellBtnAction:label:model:)]) {
        [self.delegate CarGooodsTableViewCellBtnAction:(AmountType)btn.tag label:self.countLab model:self.model];
    }
}

- (void)setModel:(NormalShopGoodsModel *)model
{
    _model = model;
    [self.iconImage sd_setImageWithURL:[NSURL URLWithString:model.thumbnailUrl] placeholderImage:GetImage(@"default_goods_image")];
    self.titleLab.text = model.name;//共3件商品 需付款:¥450元
    self.priceLab.text = [NSString stringWithFormat:@"共%zd件商品 需付款:¥%.2f元",model.productInShopCarCount,model.price*model.productInShopCarCount];
    self.countLab.text = [NSString stringWithFormat:@"%zd",model.productInShopCarCount];
    self.checkBtn.selected = model.isSelect;
}
- (void)setIsNeedsHidden:(BOOL)isNeedsHidden
{
    _isNeedsHidden = isNeedsHidden;
    self.addBtn.hidden = isNeedsHidden;
    self.minusBtn.hidden = isNeedsHidden;
    self.countLab.hidden = isNeedsHidden;
    self.titleCons.constant = 15;
    self.checkBtn.selected = YES;
    self.checkBtn.userInteractionEnabled = NO;
}
//有footer时候最下面的cell分割线会隐藏
//- (void)layoutSubviews
//{
//    [super layoutSubviews];
//    for (UIView *subview in self.contentView.superview.subviews) {
//        if ([NSStringFromClass(subview.class) hasSuffix:@"SeparatorView"]) {
//            subview.hidden = NO;
//        }
//    }
//}


@end
